//
//  WZMobileSignController.m
//  ETong
//
//  Created by wanzhao on 15/10/29.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZMobileSignController.h"
#import "NSDate+Extension.h"
#import "MBProgressHUD+WZ.h"
#import "NetWorkShare.h"
#import "WZSign.h"
#import "MJExtension.h"
#import "WZGecodeSearchShare.h"
#import "WZLoctionShare.h"
#import "CFolderMgr.h"
#import "CContactMgr.h"
#import "CContactModel.h"
#import "CAccountModel.h"
#import "NSString+fish_base64.h"
#import "NSString+fish_MD5.h"
#import "CXmppRequestMgr.h"
#import "WZOAoffice.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "FaceCertifyViewController.h"
#import "JKAlertDialog.h"
#import "WZMobileOutSignList.h"
#import "WZSignListViewController.h"
#import "WZSignWebViewController.h"
#import "WZSignListCell.h"

#define Procedure_TaleID @"wcdkspd"

@interface WZMobileSignController ()<WZGecodeSearchShareDelegate, WZLoctionShareDelegate,FaceCertifyViewControllerDelegate, UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) CContactModel *curAccount;
@property (nonatomic, weak) UIButton *dateBtn;
@property (nonatomic, weak) UIButton *timeBtn;
@property (nonatomic, weak) UIButton *addressBtn;
@property (nonatomic, weak) UILabel *signLabel;
@property (nonatomic, weak) UILabel *signOutLabel;
@property (nonatomic, weak) UIView *signView;
@property (nonatomic, weak) UIView *signOutView;
@property (nonatomic, weak) UILabel *signDetailLabel;
@property (nonatomic, weak) UILabel *signOutDetailLabel;
@property (nonatomic, weak) UIButton *sw;// 范围按钮
@property (nonatomic, copy) NSString *signFlag;
@property (nonatomic, weak) UIButton *signBtn;
@property (nonatomic, weak) UIButton *signOutBtn;
@property (nonatomic, weak) UILabel *addressLabel;
@property (nonatomic, weak) UILabel *addressOutLabel;
@property (nonatomic, strong) WZSign *signBegin;

//定位相关
@property (nonatomic, assign) CLLocationCoordinate2D userCoordiNate2D;
@property (nonatomic, copy) NSString *latitude;
@property (nonatomic, copy) NSString *longitude;
@property (nonatomic, copy) NSString *address;

@property (nonatomic, strong) NSMutableArray *mobileSignArray;

@property (nonatomic, weak) UIImageView *qiandaoImage;
@property (nonatomic, weak) UIImageView *qiantuiImage;

@property (nonatomic, weak) UIView *shijianzouView;
@property (nonatomic ,assign) BOOL isSignOrSignOut;
/**记录反地理编码是否成功*/
@property (nonatomic, assign) BOOL isRevertReo;

// 公司内部签到相关
@property (nonatomic, copy) NSString *innerIP;

// 有EFeng 获取公司ID
@property (nonatomic, copy) NSString *company_ID;

/**OA用户名*/
@property (nonatomic, copy) NSString *oaUserName;
/**OA 登陆密码*/
@property (nonatomic, copy) NSString *oaPwd;
/**OA userId*/
@property (nonatomic, copy) NSString *oaUserId;
/**OA 公司ID*/
@property (nonatomic, copy) NSString *oaCompanyID;
/**OA 姓名*/
@property (nonatomic, copy) NSString *oaName;

@property (nonatomic, copy) NSString *locatStr;

@property (nonatomic, strong) NSMutableArray *attendInfors;
@property (nonatomic, weak) UIButton *button;
@property (nonatomic, strong) NSTimer *timeNow;
@property (nonatomic, assign)BOOL playAnimation;
@property (nonatomic, strong) CContactModel *currentUser;
@property (nonatomic, assign) NSInteger faceCount;

// 手机打卡流程
@property (nonatomic, strong) NSMutableArray *listArray;
@property (nonatomic, copy) NSString *applyUrl;
@property (nonatomic, weak) UITableView *tableView;

@end

@implementation WZMobileSignController

static NSString * const identifier = @"signListCell";

- (void)dealloc
{
    NSLog(@"WZMobileSignController  dealloc");
    [[WZLoctionShare LoctionShareInstance] stopLocationService];
    [WZLoctionShare LoctionShareInstance].delegate = nil;
    [WZGecodeSearchShare geoCodeSearchShareInstance].gecodeDelegate = nil;
}
-(CContactModel *)currentUser
{
    if (_curAccount == nil) {
        _curAccount = [[[CContactMgr alloc]init] loadCurContact];
    }
    return _curAccount;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setupUI];
    
    [self addChildControl];
    
//    [self creatSignProcedureView];
   
    [self getMobileSignList];
    
    [self getIPAddressAndCheck];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (self.playAnimation) {
        [self daka:self.button];
    }
}
// setupUI
- (void)setupUI {
    
    self.view.backgroundColor = WhiteColor;
    self.navigationItem.title = @"手机考勤";
//    CAccountModel * acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
//    self.curAccount = [[[CContactMgr alloc] init] loadContactWithUserCode:acc.userName];
    
    
    // 获取OA账户信息
    self.oaUserName = [USER_DEFAULT objectForKey:@"oaUserName"];
    self.oaUserId = [USER_DEFAULT objectForKey:@"oaUserId"];
    self.oaPwd = [USER_DEFAULT objectForKey:@"oaPwd"];
    self.oaCompanyID = [USER_DEFAULT objectForKey:@"oaCompanyID"];
    self.oaName = [USER_DEFAULT objectForKey:@"oaName"];

    // E蜂 获取公司ID
//    [self getCompanyIDWithUserCode:self.curAccount.UserCode];
    
//    self.address = @"北京市朝阳区建国路甲92号世茂大厦B座";
    self.address = nil;
    self.latitude = nil;
    self.longitude = nil;
    
    [WZLoctionShare LoctionShareInstance].delegate = self;
    [WZGecodeSearchShare geoCodeSearchShareInstance].gecodeDelegate = self;
    
}


- (UITextField *)addtextField
{
    UITextField *signOutField = [[UITextField alloc] init];
    signOutField.borderStyle = UITextBorderStyleNone;
    signOutField.background = [UIImage imageNamed:@"signText"];
    signOutField.textColor = RGBCOLORWITH16COLOR(0x333333);
    signOutField.font = Font15;
    signOutField.textAlignment = NSTextAlignmentLeft;
    signOutField.leftViewMode = UITextFieldViewModeAlways;
    UIView *leftView2 = [[UIView alloc] init];
    leftView2.frame = CGRectMake(0, 0, 15.0f, 15.0f);
    leftView2.backgroundColor = ClearColor;
    signOutField.leftView = leftView2;
    signOutField.hidden = YES;
    return signOutField;
}


#pragma mark -- 定位的代理方法

/**位置更新时调用*/
// 定位经纬度
- (void)didUpdateLocation:(BMKUserLocation *)userLocation
{
    [[WZLoctionShare LoctionShareInstance] stopLocationService];
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    _isRevertReo = false;
    self.userCoordiNate2D = userLocation.location.coordinate;
    
    self.latitude = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.latitude];
    self.longitude = [NSString stringWithFormat:@"%f",userLocation.location.coordinate.longitude];
    
    BMKReverseGeoCodeOption *op = [[BMKReverseGeoCodeOption alloc] init];
    op.reverseGeoPoint = userLocation.location.coordinate;
    
    _isRevertReo = [[WZGecodeSearchShare geoCodeSearchShareInstance] wzReverseGeoCode:op];
    
}



#pragma mark -- 反地理编码代理
/**返回反地理编码结果*/
- (void)wzOnGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    //    BMK_SEARCH_NO_ERROR = 0,///<检索结果正常返回
    //    BMK_SEARCH_AMBIGUOUS_KEYWORD,///<检索词有岐义
    //    BMK_SEARCH_AMBIGUOUS_ROURE_ADDR,///<检索地址有岐义
    //    BMK_SEARCH_NOT_SUPPORT_BUS,///<该城市不支持公交搜索
    //    BMK_SEARCH_NOT_SUPPORT_BUS_2CITY,///<不支持跨城市公交
    //    BMK_SEARCH_RESULT_NOT_FOUND,///<没有找到检索结果
    //    BMK_SEARCH_ST_EN_TOO_NEAR,///<起终点太近
    //    BMK_SEARCH_KEY_ERROR,///<key错误
    //    BMK_SEARCH_NETWOKR_ERROR,///网络连接错误
    //    BMK_SEARCH_NETWOKR_TIMEOUT,///网络连接超时
    //    BMK_SEARCH_PERMISSION_UNFINISHED,///还未完成鉴权，请在鉴权通过后重试
    
//    for (BMKPoiInfo *info in result.poiList) {
//        
//        WZLog(@"%@=%@",info.name,info.address);
//    }
    
//       WZLog(@"%@＝%@＝%@＝%@＝%@＝%@＝%@",result.addressDetail.streetName,result.addressDetail.streetNumber,result.addressDetail.district,result.addressDetail.city,result.addressDetail.province,result.address,result.businessCircle);
    if (error == BMK_SEARCH_NO_ERROR) {
        
        [MBProgressHUD hideHUD];
        self.address = result.address;
        [self.addressBtn setTitle:result.address forState:UIControlStateNormal];
    }
}



#pragma mark -- 初始化视图
- (void)setupData
{
    if (self.mobileSignArray.count <= 0) { // 当天无签到列表
        self.signView.hidden = YES;
        self.signOutView.hidden = YES;
    } else { // 当天有签到列表
        
        self.signView.hidden = YES;
        self.qiandaoImage.hidden = YES;
//        self.signBtn.enabled = NO;

        if (self.mobileSignArray.count == 1) {// 有打卡记录时 判断
            
            [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                
                return [obj1.sign compare:obj2.sign];
            }];
            
            WZSign *sign = self.mobileSignArray.firstObject;
            if ([@"1" isEqualToString:sign.sign]) { // 上班已打卡, 显示打卡视图
                self.signLabel.text = [NSString stringWithFormat:@"%@  上班签到",sign.time];
                self.signDetailLabel.text = sign.address;
                self.signDetailLabel.height = [sign.address sizeWithFont:Font12 maxSize:CGSizeMake(self.signDetailLabel.width, MAXFLOAT)].height;
                self.signView.hidden = NO;
                self.qiandaoImage.hidden = NO;
                self.signBtn.enabled = NO; // 设置签到不能点击

            } else if ([@"2" isEqualToString:sign.sign]) { // 下班已打卡
                self.signOutLabel.text = [NSString stringWithFormat:@"%@  下班签退",sign.time];
                self.signOutDetailLabel.text = sign.address;
                self.signOutDetailLabel.height = [sign.address sizeWithFont:Font12 maxSize:CGSizeMake(self.signOutDetailLabel.width, MAXFLOAT)].height;
                self.signOutView.hidden = NO;
                self.qiantuiImage.hidden = NO;
                
                
            } else { // 其他
                self.signLabel.text = [NSString stringWithFormat:@"%@  上班签到",sign.time];
                self.signDetailLabel.text = sign.address;
                self.signDetailLabel.height = [sign.address sizeWithFont:Font12 maxSize:CGSizeMake(self.signDetailLabel.width, MAXFLOAT)].height;
                self.signView.hidden = NO;
                self.qiandaoImage.hidden = NO;
//                self.signBtn.enabled = NO;

            }
            
        } else { // 签到列表中有多个值
            
            WZSign *signBegin = self.mobileSignArray.firstObject;
            if (![@"2" isEqualToString:signBegin.sign]) { // 上班已经打卡
                
                // 设置上班签到的视图
                self.signLabel.text = [NSString stringWithFormat:@"%@  上班签到",signBegin.time];
                self.signDetailLabel.text = signBegin.address;
                self.signDetailLabel.height = [signBegin.address sizeWithFont:Font12 maxSize:CGSizeMake(self.signDetailLabel.width, MAXFLOAT)].height;
                self.signView.hidden = NO;
                self.qiandaoImage.hidden = NO;
                self.signBtn.enabled = NO;
            }
            
            WZSign *signEnd = self.mobileSignArray.lastObject;
            if (![@"1" isEqualToString:signEnd.sign]) { // 下班打卡视图
                self.signOutLabel.text = [NSString stringWithFormat:@"%@  下班签退",signEnd.time];
                self.signOutDetailLabel.text = signEnd.address;
                self.signOutDetailLabel.height = [signEnd.address sizeWithFont:Font12 maxSize:CGSizeMake(self.signOutDetailLabel.width, MAXFLOAT)].height;
                self.signOutView.hidden = NO;
                self.qiantuiImage.hidden = NO;
            }
        }
    }
}


#pragma mark -- 获取IP站点
- (void)getIPAddressAndCheck {
    
    [NetWorkShare getIpAddressWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            
            if ([[responseObject objectForKey:@"result"] boolValue]) {
                
                WZLog(@"获取的站点:resultInfo = %@", responseObject);

                NSString *result = [responseObject objectForKey:@"resultInfo"];
                NSArray *addArray = [result componentsSeparatedByString:@";"];
                
//                NSArray *strArr = [ipArray componentsSeparatedByString:@","];
//                NSString *base64IpID = [NSString base64Encode:strArr.lastObject];
//                NSString *base64ComID = [NSString base64Encode:self.company_ID]; // 登录E蜂
//                
//                OA 公司ID
//                NSString *compID = @"4028fbab55818e110155818e9eca0000";
//                NSString *base64comID = [NSString base64Encode:compID];

                
                // 循环遍历iP
                NSMutableArray *tempArray = [NSMutableArray array];
                for (NSString *str in addArray) {
                    NSString *ipStr = [str componentsSeparatedByString:@","].firstObject;
                    NSString *idStr = [str componentsSeparatedByString:@","][1];
                    NSString *companyName = [str componentsSeparatedByString:@","].lastObject;
                    
                    NSString *base64IpID = [NSString base64Encode:idStr];
                    NSString *base64comID = [NSString base64Encode:self.oaCompanyID];
                    NSString *address = [NSString stringWithFormat:@"http://%@:8080/%@,%@",ipStr, base64comID,base64IpID];
                    
                    NSString *innerIP = [NSString generateUrl:address];
                    
                    NSString *attendInfor = [NSString stringWithFormat:@"%@;%@", innerIP, companyName];
                    
                    [tempArray addObject:attendInfor];
                    
                    WZLog(@"innerIP = %@", attendInfor);
                }
                
                self.attendInfors = tempArray.copy;
                
            } else {
                
                // 没有符合的站点
                [MBProgressHUD showError:[responseObject objectForKey:@"resultInfo"]];
            }
        } else {
            [MBProgressHUD showError:UNKNOWNERROR];
        }
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
//        [MBProgressHUD showError:NETWORKNERROR];
    }];
}



#pragma mark -- 加载数据
- (void)getMobileSignList
{
    
    [MBProgressHUD showMessage:@"数据加载中..." toView:self.view];
    [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view];
        if (responseObject) {
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                [self.mobileSignArray removeAllObjects];
                [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                
                WZLog(@"= %@, %@, %@", [self.mobileSignArray class], self.mobileSignArray.firstObject, [self.mobileSignArray.firstObject class]);
                
                [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                    
                    return [obj1.sign compare:obj2.sign];
                }];
                
                WZLog(@"list = %@-- 打卡列表数组为 = %@",responseObject, self.mobileSignArray);
                if (self.mobileSignArray.count > 0) {
                    [self setupData];
                }
                
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
            
        } else {
            [MBProgressHUD showError:@"未知错误"];
        }

    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络错误!" toView:self.view];
    }];
}


#pragma mark -- 按钮点击
- (void)btnClick:(UIButton *)btn
{
    self.playAnimation = NO;
    self.button = btn;
    if (!(btn.tag == 10001||btn.tag == 10002)) {
        [self daka:btn];
    }
    else
    {
        [self daka:btn];
        return;
    if ([self isSupportfinger]) {
        __weak typeof (self) weakself = self;
        LAContext* context = [[LAContext alloc] init];
        context.localizedFallbackTitle = @"";
        NSString* result = @"请验证您的指纹打卡";
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
            if (success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakself daka:btn];
                });
                
            }
            else
            {
                switch (error.code) {
                    case LAErrorSystemCancel:
                    {
                        break;
                    }
                    case LAErrorUserCancel:
                    {
                        NSLog(@"Authentication was cancelled by the user");
                        //用户取消验证Touch ID
                        break;
                    }
                    case LAErrorUserFallback:
                    {
                        NSLog(@"User selected to enter custom password");
                        break;
                    }
                    default:
                    {
                        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                            //其他情况，切换主线程处理
                        }];
                        break;
                    }
                }
            }
        }];

        
    }
        else
        {
            if ([USER_DEFAULT boolForKey:@"haveFace"]) {
                FaceCertifyViewController *face = [[FaceCertifyViewController alloc]init];
                face.delegate = self;
                face.button = btn;
                [self presentViewController:face animated:YES completion:nil];
 
            }
            else
            {
                JKAlertDialog *alert = [[JKAlertDialog alloc]initWithTitle:@"温馨提示" message:@"请到 我->设置->安全与隐私->人脸识别 中添加您的脸谱"];
                [alert addButton:Button_OK withTitle:@"确定" handler:^(JKAlertDialogItem *item) {
                    
                }];
                [alert show];

            }
        }
    }
}
-(void)Verificationsuccessfulwithbutton:(UIButton *)button
{
    self.playAnimation = YES;
}
//打卡
-(void)daka:(UIButton*)btn
{
    switch (btn.tag) {
            //上班签到
        case 10001:
        {
            self.signView.hidden = YES;
            self.qiandaoImage.hidden = YES;
            self.signFlag = @"1";
            //            self.signBtn.enabled = NO;
        }
            break;
            //下班签退
        case 10002:
        {
            //            self.signOutView.hidden = YES;
            //            self.qiantuiImage.hidden = YES;
            self.signFlag = @"2";
        }
            break;
            //范围选择
        case 10003:
        {
            btn.selected = !btn.selected;
            
            if (btn.selected) {
                
                [MBProgressHUD showMessage:@"定位中..." toView:self.view];
                // 开启定位
                self.addressBtn.titleLabel.text = nil;
                self.address = nil;
                [[WZLoctionShare LoctionShareInstance] startLocationService];
                self.addressBtn.hidden = NO;
                [self.addressBtn setTitle:@"正在定位..." forState:UIControlStateNormal];
                
            } else {
                
                [MBProgressHUD hideHUD];
                self.addressBtn.hidden = YES;
            }
        }
            break;
            
        default:
            break;
    }
    
#pragma mark -- 上下班打卡
    // 签到签退
    if (btn.tag == 10001 || btn.tag == 10002) {
        
        if (self.sw.isSelected) { // 外出手机签到
            
/*********** 外出手机打卡走工作流逻辑 ***********/
            
            [NetWorkShare getWorkFlowWithApplyAndLoginName:self.oaUserName password:self.oaPwd companyId:self.oaCompanyID FormId:Procedure_TaleID successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                
                if ([[responseObject objectForKey:@"success"] boolValue]) {
                    
                    [MBProgressHUD hideHUDForView:self.view];
                    [self.listArray removeAllObjects];
                    self.listArray = [WZMobileOutSignList objectArrayWithKeyValuesArray:responseObject[@"datas"]];
                    
                    self.applyUrl = responseObject[@"applyUrl"];
                    
                    WZLog(@"count = %lu", (unsigned long)self.listArray.count);
                    NSNumber *num = [NSNumber numberWithUnsignedInteger:self.listArray.count];
                    [[NSNumber numberWithUnsignedInteger:self.listArray.count] isEqualToNumber:@(0)];
                    WZLog(@"%@", num);
                    
                    if (!self.listArray.count) {
                        
                        // TODO: 没有流程
                        [MBProgressHUD showError:@"没有相关流程"];
                        
                    } else {
                        
                        if (self.listArray.count > 1) {
                            
//                            self.tableView.hidden = NO;
                            [self.view setNeedsDisplay];
                            WZSignListViewController *applyVc = [[WZSignListViewController alloc] init];
                            applyVc.formId = Procedure_TaleID;
                            applyVc.oaUserName = self.oaUserName;
                            applyVc.oaPwd = self.oaPwd;
                            applyVc.oaCompanyID = self.oaCompanyID;
                            applyVc.oaUserName = self.oaUserName;
                            applyVc.signFlag = self.signFlag;
                            applyVc.userCoordiNate2D = self.userCoordiNate2D;
                            applyVc.oaUserId = self.oaUserId;
                            applyVc.block = ^(BOOL isSuccess){
                                
                                [self stampSignView];
                            };
                            
                            [self.navigationController pushViewController:applyVc animated:YES];
                            
                        } else if (self.listArray.count == 1 && [[self.listArray.firstObject runState] isEqualToString:@"运行中"]) {
                            
                            // 直接打开
                            NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
                            parameters[@"userId"] = self.oaUserId;
                            parameters[@"signFlag"] = self.signFlag;
                            parameters[@"longitude"] = [NSString stringWithFormat:@"%f",self.userCoordiNate2D.longitude];
                            parameters[@"latitude"] = [NSString stringWithFormat:@"%f",self.userCoordiNate2D.latitude];
                            WZMobileOutSignList *signList = self.listArray.lastObject;
                            parameters[@"modelId"] = signList.modelId;
                            parameters[@"mversion"] = signList.mversion;
                            parameters[@"fversion"] = signList.fversion;
                            parameters[@"startEventkey"] = signList.startEventKey;
                            
                            [NetWorkShare OutMobileSignOrSignOutProcedureWithParameters:parameters successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                                if ([[responseObject objectForKey:@"success"] boolValue]) {
                                    
                                    [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                                        [MBProgressHUD hideHUDForView:self.view];
                                        if (responseObject) {
                                            NSLog(@"+++ = %@", responseObject);
                                            if ([[responseObject objectForKey:@"success"] boolValue]) {
                                                [self.mobileSignArray removeAllObjects];
                                                [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                                                
                                                //数组排序
                                                [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                                                    return [obj1.sign compare:obj2.sign];
                                                }];
                                                
                                                if ([@"1" isEqualToString:self.signFlag]) {
                                                    self.qiandaoImage.hidden = NO;
                                                    [self addAnimationWithImageview:self.qiandaoImage];
                                                    [self setupData];
                                                } else {
                                                    self.qiantuiImage.hidden = NO;
                                                    
                                                    [self addAnimationWithImageview:self.qiantuiImage];
                                                    [self setupData];
                                                }
                                                
                                            } else {
                                                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
                                            }
                                            
                                        } else {
                                            [MBProgressHUD showError:@"未知错误"];
                                        }
                                        
                                    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                                        [MBProgressHUD hideHUDForView:self.view];
                                        [MBProgressHUD showError:@"网络错误!" toView:self.view];
                                    }];
                                    
                                } else {
                                    
                                    [MBProgressHUD hideHUDForView:self.view];
                                    [MBProgressHUD showError:[responseObject objectForKey:@"message"] toView:self.view];
                                }
                                
                            } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                                [MBProgressHUD hideHUDForView:self.view];
                                [MBProgressHUD showError:@"网络错误!" toView:self.view];
                            }];
                            
                        
                            /*
                            NSString *applyURLStr = [[NSString stringWithFormat:@"http:%@/OA_CBD%@&formid=%@&workFlowflag=%@&mversion=%@&taskdef=%@&fversion=%@",SERVERIP, self.applyUrl, [self.listArray.firstObject formKey], [self.listArray.firstObject modelId], [self.listArray.firstObject mversion], [self.listArray.firstObject startEventKey], [self.listArray.firstObject fversion]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                            
                            NSString *autho = [[[NSString stringWithFormat:@"%@:%@:%@", self.oaUserName, self.oaPwd, self.oaCompanyID] dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
                            NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:applyURLStr]];
                            
                            [req addValue:[NSString stringWithFormat:@"Basic %@", autho] forHTTPHeaderField:@"Authorization"];
                            
                            NSURLRequest *request = [req copy];
                            WZSignWebViewController *web = [[WZSignWebViewController alloc] init];
                            // TODO: 传入流程名称
                            // web.proDetail = detail;
                            web.request = request;
                            
                            [self.navigationController pushViewController:web animated:YES];
                            */
                        }
                        
                    }
                    
                    
                } else {
                    
                    [MBProgressHUD hideHUDForView:self.view];
                    [MBProgressHUD showError:[responseObject objectForKey:@"message"] toView:self.view];
                }
                
            } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                [MBProgressHUD hideHUDForView:self.view];
                [MBProgressHUD showError:NETWORKNERROR toView:self.view];
            }];

            
/*********** 正常手机外出打卡, 未走工作流逻辑 ***********
           
            [NetWorkShare OutMobileSignOrSignOutWithUserId:self.oaUserId signFlag:self.signFlag address:self.address successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                
                if (responseObject) {
                    
                    if ([[responseObject objectForKey:@"success"] boolValue])
                    {
                        [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                            [MBProgressHUD hideHUDForView:self.view];
                            if (responseObject) {
                                NSLog(@"+++ = %@", responseObject);
                                if ([[responseObject objectForKey:@"success"] boolValue]) {
                                    [self.mobileSignArray removeAllObjects];
                                    [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                                    
                                    //数组排序
                                    [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                                        return [obj1.sign compare:obj2.sign];
                                    }];
                                    
                                    if ([@"1" isEqualToString:self.signFlag]) {
                                        self.qiandaoImage.hidden = NO;
                                        [self addAnimationWithImageview:self.qiandaoImage];
                                        [self setupData];
                                    } else {
                                        self.qiantuiImage.hidden = NO;
                                        
                                        [self addAnimationWithImageview:self.qiantuiImage];
                                        [self setupData];
                                    }
                                    
                                } else {
                                    [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
                                }
                                
                            } else {
                                [MBProgressHUD showError:@"未知错误"];
                            }
                            
                        } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                            [MBProgressHUD hideHUDForView:self.view];
                            [MBProgressHUD showError:@"网络错误!" toView:self.view];
                        }];
                        
                    } else {
                        [MBProgressHUD hideHUDForView:self.view];
                        [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
                    }
                    
                } else {
                    [MBProgressHUD hideHUDForView:self.view];
                    [MBProgressHUD showError:@"未知错误"];
                }
                
            } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                [MBProgressHUD hideHUDForView:self.view];
                [MBProgressHUD showError:@"网络错误!" toView:self.view];
            }];
 
 
************ END ***********/
            
        } else { // 公司内手机签到
            
#pragma mark -- 公司内手机打卡
            // 判断公司内服务器站点是否为空
            if (self.attendInfors.count > 0) {
                
                for (NSString *attendIfor in self.attendInfors) {
                    
                    NSString *attendIP = [attendIfor componentsSeparatedByString:@";"].firstObject;
                    
                    __weak typeof(self) weakSelf = self;
                    // 验证接口
                    NSURL *url = [NSURL URLWithString:attendIP];
                    NSURLRequest *request = [NSURLRequest requestWithURL:url];
                    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
                        
                        NSDictionary *headerDict = [(NSHTTPURLResponse *)response allHeaderFields];
                        
                        NSString *locaStr = headerDict[@"Location"];
                        
                        if ([locaStr hasSuffix:@"0"]) {
                            
                            WZLog(@"可用的IP地址是: %@", attendIP);
                            self.address = [attendIfor componentsSeparatedByString:@";"].lastObject;
                            
                            // 公司内签到签退
                            [NetWorkShare mobileSignOrSignOutWithUserId:self.oaUserId signFlag:self.signFlag address:self.address successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                                
                                if (responseObject) {
                                    
                                    if ([[responseObject objectForKey:@"success"] boolValue]) {
                                        
                                        WZLog(@"公司内打卡接口 = %@", responseObject);
                                        
                                        // 获取签到列表
                                        [NetWorkShare getMobileCurdaySignListWithUserId:weakSelf.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                                            [MBProgressHUD hideHUDForView:weakSelf.view];
                                            if (responseObject) {
                                                
                                                if ([[responseObject objectForKey:@"success"] boolValue]) {
                                                    [weakSelf.mobileSignArray removeAllObjects];
                                                    [weakSelf.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                                                    
                                                    // 数组排序
                                                    [weakSelf.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                                                        return [obj1.sign compare:obj2.sign];
                                                    }];
                                                    
                                                    WZLog(@"手机签到列表接口 = %@", responseObject);
                                                    
                                                    if ([@"1" isEqualToString:weakSelf.signFlag]) { // 签到
                                                        weakSelf.qiandaoImage.hidden = NO;
                                                        [weakSelf addAnimationWithImageview:weakSelf.qiandaoImage];
                                                        [weakSelf setupData];
                                                        
                                                        self.signBtn.enabled = NO;
                                                        
                                                    } else { // 签退
                                                        
                                                        weakSelf.qiantuiImage.hidden = NO;
                                                        
                                                        [weakSelf addAnimationWithImageview:self.qiantuiImage];
                                                        [weakSelf setupData];
                                                    }
                                                } else {
                                                    [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
                                                }
                                                
                                            } else {
                                                [MBProgressHUD showError:@"未知错误"];
                                            }
                                            
                                            WZLog(@"+==========打卡成功!");
                                            
                                            weakSelf.signOutBtn.enabled = NO;
                                            
                                            [weakSelf performSelector:@selector(signOutBtnChanged) withObject:nil afterDelay:30.0f];
                                            
                                        } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            [MBProgressHUD hideHUDForView:weakSelf.view];
                                            [MBProgressHUD showError:@"网络错误!" toView:weakSelf.view];
#pragma mark -- 签退按钮处理
                                        }];
                                        
                                    } else {
                                        [MBProgressHUD hideHUDForView:weakSelf.view];
                                        [MBProgressHUD showError:@"公司内打卡失败"];
                                    }
                                    
                                } else {
                                    [MBProgressHUD hideHUDForView:weakSelf.view];
                                    [MBProgressHUD showError:@"公司内打卡未知错误"];
                                }
                                
                                
                            } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                                [MBProgressHUD hideHUDForView:weakSelf.view];
                                [MBProgressHUD showError:@"网络错误!"];
                            }];
                            
                            return ;
                            
                        } else {
                            
                                [MBProgressHUD showError:@"获取考勤站点错误!"];
                        }
                        
                    }];
                    
                }
                
            } else {
                
                [MBProgressHUD showError:@"获取站点IP错误!"];
                WZLog(@"获取站点IP错误!");
            }
        }
    }

}

// 检查手机认证
- (void)checkMoblieAuthorize {
    
    [NetWorkShare checkMobileWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [MBProgressHUD hideHUDForView:nil];
        
        NSString *mobileStr = @"";
        if (responseObject) {
            NSString *status =  [NSString stringWithFormat:@"%@",responseObject[@"status"]];
            if ([[responseObject objectForKey:@"success"] boolValue]) { // 0 代表没有认证
                
                if ([status isEqualToString:@"2"]) {
                    mobileStr = @"已认证";
                    WZLog(@"%@", mobileStr);
                } else {
                    
                }
                
            } else {
                
                if ([status isEqualToString:@"-1"]) {
                    
                    [MBProgressHUD showError:responseObject[@"message"]];
                    WZLog(@"没有对应的用户");
                } else if ([status isEqualToString:@"0"]) {
                    [MBProgressHUD showError:responseObject[@"message"]];
                    WZLog(@"手机未认证");
                } else if ([status isEqualToString:@"1"]) {
                    mobileStr = @"待审核";
                    WZLog(@"待审核");
                } else if ([status isEqualToString:@"3"]) {
                    mobileStr = @"审核被拒绝";
                    WZLog(@"审核被拒绝");
                }
                
            }
            
        } else {
            
        }
        
        [USER_DEFAULT setObject:mobileStr forKey:ISMOBILEAVALable];
        [USER_DEFAULT synchronize];
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUDForView:nil];
        
    }];
}


#pragma mark -- 时间戳添加动画
- (void)addAnimationWithImageview:(UIImageView *)imageView
{
    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    
    // 向动画组中添加动画
    // 路径动画
    CAKeyframeAnimation *anim1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    NSValue *p1 = [NSValue valueWithCGPoint:CGPointMake(self.shijianzouView.width / 2.0f, self.shijianzouView.height / 2.0f)];
    NSValue *p2 = [NSValue valueWithCGPoint:CGPointMake(imageView.centerX + 80.0f, imageView.centerY + 80.0f)];
    
    NSValue *p3 = [NSValue valueWithCGPoint:imageView.center];
    
    anim1.values = @[p1,p2,p3];
    

    CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
    anim2.fromValue = @(1.0f);
    anim2.toValue = @(self.shijianzouView.width / 80.0f);
    
    CABasicAnimation *anim3 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    anim3.fromValue = @(1.0f);
    anim3.toValue = @(self.shijianzouView.height / 80.0f);
    
   
    CABasicAnimation *anim5 = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
    anim5.fromValue = @(self.shijianzouView.width / 80.0f);
    anim5.toValue = @(1.0f);
    
    CABasicAnimation *anim6 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    anim6.fromValue = @(self.shijianzouView.height / 80.0f);
    anim6.toValue = @(1.0f);

    
//    CAKeyframeAnimation *anim4 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//   NSValue *p2 = [NSValue valueWithCGPoint:imageView.center];
//    anim4.values = @[p2];

    // 旋转动画
//    CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//    anim2.toValue = @(M_PI * 10);
    
    // 缩放动画
    
//    CABasicAnimation *anim4 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//    anim4.fromValue = @(4.0f);
//    anim4.toValue = @(1.0f);

    
    group.animations = @[anim2, anim3,anim1,anim5,anim6];
    
    // 动画时长，一组动画整体完成的时间
    group.duration = 1.0f;
    
    [imageView.layer addAnimation:group forKey:nil];

}


- (UIButton *)addButtonWithImageName:(NSString *)imageName
{
    UIButton *dateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    dateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [dateBtn setTitleColor:RGBCOLORWITH16COLOR(0x666666) forState:UIControlStateNormal];
    dateBtn.titleLabel.font = Font11;
    dateBtn.userInteractionEnabled = NO;
    [dateBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    dateBtn.titleEdgeInsets = UIEdgeInsetsMake(0, OppositeWidthRate(10), 0, 0);
    [self.view addSubview:dateBtn];
    return dateBtn;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!IsIOS7) {
        self.navigationController.navigationBar.tintColor = RGBCOLORWITH16COLOR(0xf56271);
    } else {
        self.navigationController.navigationBar.barTintColor = RGBCOLORWITH16COLOR(0xf56271);
    }
}


#pragma mark -- 获取当天手机签到列表
- (void) getCurrentSignListWith {
    
    [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view];
        if (responseObject) {
            NSLog(@"+++ = %@", responseObject);
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                [self.mobileSignArray removeAllObjects];
                [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                if ([@"1" isEqualToString:self.signFlag]) {
                    self.qiandaoImage.hidden = NO;
                    [self addAnimationWithImageview:self.qiandaoImage];
                    [self setupData];
                } else {
                    self.qiantuiImage.hidden = NO;
                    
                    [self addAnimationWithImageview:self.qiantuiImage];
                    [self setupData];
                }
                
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
            
        } else {
            [MBProgressHUD showError:@"未知错误"];
        }
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络错误!" toView:self.view];
    }];
    

}


/**初始化子控件*/
- (void)addChildControl {
    
    //用户头像
    UIImageView *touxingImage = [[UIImageView alloc] init];
    touxingImage.frame = CGRectMake(OppositeWidthRate(15), OppositeHeightRate(8), OppositeWidthRate(64), OppositeWidthRate(64));
    touxingImage.image = [UIImage imageNamed:@"title"];
    touxingImage.layer.cornerRadius = 8.0f;
    touxingImage.layer.masksToBounds = YES;
    [self.view addSubview:touxingImage];
    
    //用户姓名
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.frame = CGRectMake(CGRectGetMaxX(touxingImage.frame) + 13.5f, 0, self.view.width - OppositeWidthRate(30) - OppositeWidthRate(64), OppositeHeightRate(80));
    nameLabel.numberOfLines = 0;
    nameLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    nameLabel.font = Font17;
    nameLabel.textAlignment = UITextAlignmentLeft;
    nameLabel.text = self.oaName;
    
    [self.view addSubview:nameLabel];
    
    
    //范围选择按钮
    UIButton *sw = [UIButton buttonWithType:UIButtonTypeCustom];
    [sw setImage:[UIImage imageNamed:@"mobileSignSwitchOff"] forState:UIControlStateNormal];
    [sw setImage:[UIImage imageNamed:@"mobileSignSwitchOn"] forState:UIControlStateSelected];
    sw.adjustsImageWhenHighlighted = NO;
    sw.tag = 10003;
    [sw addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    sw.frame = CGRectMake(self.view.width - OppositeWidthRate(15) - sw.currentImage.size.width, (OppositeHeightRate(80) - sw.currentImage.size.height) / 2.0f , sw.currentImage.size.width, sw.currentImage.size.height);
    [self.view addSubview:sw];
    self.sw = sw;
    
    //范围选择label
    UILabel *label = [[UILabel alloc] init];
    label.text = @"公司范围外";
    label.textColor = RGBCOLORWITH16COLOR(0x666666);
    label.textAlignment = UITextAlignmentRight;
    label.font = Font11;
    label.frame = CGRectMake(sw.x - 60.0f - 5.0f, sw.y, 60, sw.height);
    [self.view addSubview:label];
    
    NSDate *curdate = [NSDate date];
    NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.timeZone = [NSTimeZone systemTimeZone];
    fm.locale = [NSLocale currentLocale];
    
    //划线
    UIView *line = [[UIView alloc] init];
    line.frame = CGRectMake(OppositeWidthRate(15), CGRectGetMaxY(nameLabel.frame), self.view.width - OppositeWidthRate(30), 0.5f);
    line.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
    [self.view addSubview:line];
    
    //日期显示按钮
    UIButton *dateBtn = [self addButtonWithImageName:@"singDateBtn"];
    dateBtn.frame = CGRectMake(OppositeWidthRate(15), CGRectGetMaxY(line.frame),OppositeWidthRate(160), OppositeHeightRate(30));
    fm.dateFormat = @"yyyy-MM-dd EEEE";
    [dateBtn setTitle:[fm stringFromDate:curdate] forState:UIControlStateNormal];
    self.dateBtn = dateBtn;
    
    //时间显示按钮
    UIButton *timeBtn = [self addButtonWithImageName:@"signtimeBtn"];
    timeBtn.frame = CGRectMake(self.view.width - OppositeWidthRate(15) - OppositeWidthRate(120), CGRectGetMaxY(line.frame), OppositeWidthRate(150), OppositeHeightRate(30));
    fm.dateFormat = @"HH:mm:ss";
    [timeBtn setTitle:[NSString stringWithFormat:@"当前时间:%@",[fm stringFromDate:curdate]] forState:UIControlStateNormal];
    self.timeNow = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    self.timeBtn = timeBtn;
    
    //地址显示按钮
    UIButton *addressBtn = [self addButtonWithImageName:@"singAddressBtn"];
    [addressBtn setTitle:self.address forState:UIControlStateNormal];
    addressBtn.frame = CGRectMake(OppositeWidthRate(15), CGRectGetMaxY(timeBtn.frame), self.view.width - OppositeWidthRate(30), OppositeHeightRate(30));
    addressBtn.hidden = YES;
    self.addressBtn = addressBtn;
    
    //划线
    UIView *line2 = [[UIView alloc] init];
    line2.frame = CGRectMake(0, CGRectGetMaxY(addressBtn.frame) + OppositeHeightRate(7), self.view.width, 0.5f);
    line2.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
    [self.view addSubview:line2];
    
    //上班签到按钮
    UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [signBtn setBackgroundImage:[UIImage imageNamed:@"signNormal"] forState:UIControlStateNormal];
    [signBtn setBackgroundImage:[UIImage imageNamed:@"signHighlighted"] forState:UIControlStateHighlighted];
    [signBtn setBackgroundImage:[UIImage imageNamed:@"signDisAbled"] forState:UIControlStateDisabled];
    signBtn.tag = 10001;
    signBtn.frame = CGRectMake(OppositeWidthRate(15), HARDWARE_SCREEN_HEIGHT - 64 - OppositeHeightRate(8) - 34.0f, 140.0f, 34.0f);
    [signBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:signBtn];
    self.signBtn = signBtn;
    
    //划线
    UIView *line3 = [[UIView alloc] init];
    line3.frame = CGRectMake(0, signBtn.y - OppositeHeightRate(8), self.view.width, 0.5f);
    line3.backgroundColor = RGBCOLORWITH16COLOR(0xe5e5e5);
    [self.view addSubview:line3];
    
    
    //下班签退
    UIButton *signOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [signOutBtn setBackgroundImage:[UIImage imageNamed:@"signOutNormal"] forState:UIControlStateNormal];
    [signOutBtn setBackgroundImage:[UIImage imageNamed:@"signOutHighligted"] forState:UIControlStateHighlighted];
    [signOutBtn setBackgroundImage:[UIImage imageNamed:@"signOutDisabled"] forState:UIControlStateDisabled];
    signOutBtn.tag = 10002;
    signOutBtn.frame = CGRectMake(self.view.width - 140.0f - OppositeWidthRate(15), HARDWARE_SCREEN_HEIGHT - 64 - OppositeHeightRate(8) - 34.0f, 140.0f, 34.0f);
    [signOutBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:signOutBtn];
    self.signOutBtn = signOutBtn;
    
#pragma mark --  显示上下班时间
    //时间轴视图
    UIView *shijianzouView = [[UIView alloc] init];
    shijianzouView.backgroundColor = RGBCOLORWITH16COLOR(0xf5f5f5);
    [self.view addSubview:shijianzouView];
    shijianzouView.frame = CGRectMake(0, CGRectGetMaxY(line2.frame), self.view.width, line3.y - CGRectGetMaxY(line2.frame));
    
    //时间轴rate
    CGFloat shijianzhouRate = shijianzouView.height / 308;
    
    //添加时间轴
    UIImageView *shijianzhou = [[UIImageView alloc] init];
    shijianzhou.image = [UIImage imageNamed:@"shijianzhou"];
    shijianzhou.frame = CGRectMake(OppositeWidthRate(15), 0, shijianzhouRate * 40, shijianzouView.height);
    [shijianzouView addSubview:shijianzhou];
    self.shijianzouView = shijianzouView;
    
    //实际签到text
    UIView *signView = [[UIView alloc] init];
    signView.hidden = YES;
    signView.backgroundColor = WhiteColor;
    signView.frame = CGRectMake(CGRectGetMaxX(shijianzhou.frame) + OppositeWidthRate(15), 32 * shijianzhouRate, shijianzouView.width - OppositeWidthRate(30) - CGRectGetMaxX(shijianzhou.frame), OppositeHeightRate(80));
    [shijianzouView addSubview:signView];
    self.signView = signView;
    
    
    //    //印章view
    //    UIButton *yinzhangView = [UIButton buttonWithType:UIButtonTypeCustom];
    //    yinzhangView.userInteractionEnabled = NO;
    //    yinzhangView.frame = CGRectMake(signView.width - OppositeWidthRate(15) - 80.0f, 0, 80.0f, 80.0f);
    //    [yinzhangView setImage:[UIImage imageNamed:@"bigYinzhang"] forState:UIControlStateNormal];
    //    [signView addSubview:yinzhangView];
    
    
    UILabel *signField = [[UILabel alloc] init];
    signField.frame = CGRectMake(OppositeWidthRate(10), OppositeHeightRate(15), signView.width - OppositeWidthRate(20),OppositeHeightRate(Font15.lineHeight));
    signField.font = Font12;
    signField.textColor = RGBCOLORWITH16COLOR(0x333333);
    signField.numberOfLines = 0;
    [signView addSubview:signField];
    self.signLabel = signField;
    
    UILabel *addressLabel = [[UILabel alloc] init];
    addressLabel.text = @"地址：";
    CGSize addressSize = [addressLabel.text sizeWithFont:Font12 maxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
    addressLabel.frame = CGRectMake(OppositeWidthRate(10), CGRectGetMaxY(signField.frame) + OppositeHeightRate(15), addressSize.width, OppositeHeightRate(Font12.lineHeight));
    addressLabel.font = Font12;
    addressLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    [signView addSubview:addressLabel];
    self.addressLabel = addressLabel;
    
    UILabel *detailAddressLabel = [[UILabel alloc] init];
    detailAddressLabel.numberOfLines = 0;
    detailAddressLabel.frame = CGRectMake(CGRectGetMaxX(addressLabel.frame), addressLabel.y, signView.width - OppositeWidthRate(10) -  CGRectGetMaxX(addressLabel.frame), OppositeHeightRate(Font12.lineHeight) * 2);
    detailAddressLabel.font = Font12;
    detailAddressLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    [signView addSubview:detailAddressLabel];
    signView.height = CGRectGetMaxY(detailAddressLabel.frame) + OppositeHeightRate(10);
    self.signDetailLabel = detailAddressLabel;
    
    
    //实际签退text
    UIView *signOutView = [[UIView alloc] init];
    signOutView.hidden = YES;
    signOutView.backgroundColor = WhiteColor;
    signOutView.frame = CGRectMake(CGRectGetMaxX(shijianzhou.frame) + OppositeWidthRate(15), 194 * shijianzhouRate, shijianzouView.width - OppositeWidthRate(30) - CGRectGetMaxX(shijianzhou.frame), OppositeHeightRate(80));
    [shijianzouView addSubview:signOutView];
    self.signOutView = signOutView;
    
    //    UIButton *yinzhangSignOutView = [UIButton buttonWithType:UIButtonTypeCustom];
    //    yinzhangSignOutView.frame = CGRectMake(signOutView.width - OppositeWidthRate(15) - 80.0f, 0, 80, 80);
    //    [yinzhangSignOutView setImage:[UIImage imageNamed:@"bigSignOutYinzhang"] forState:UIControlStateNormal];
    //    yinzhangSignOutView.userInteractionEnabled = NO;
    //    [signOutView addSubview:yinzhangSignOutView];
    
    
    UILabel *signOutField = [[UILabel alloc] init];
    signOutField.frame = CGRectMake(OppositeWidthRate(10), OppositeHeightRate(15), signView.width - OppositeWidthRate(20),OppositeHeightRate(Font12.lineHeight));
    signOutField.font = Font12;
    signOutField.textColor = RGBCOLORWITH16COLOR(0x333333);
    signOutField.numberOfLines = 0;
    [signOutView addSubview:signOutField];
    self.signOutLabel = signOutField;
    
    UILabel *addressOutLabel = [[UILabel alloc] init];
    addressOutLabel.text = @"地址：";
    addressOutLabel.frame = CGRectMake(OppositeWidthRate(10), CGRectGetMaxY(signOutField.frame) + OppositeHeightRate(15), addressSize.width, OppositeHeightRate(Font12.lineHeight));
    addressOutLabel.font = Font12;
    addressOutLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    [signOutView addSubview:addressOutLabel];
    self.addressOutLabel = addressOutLabel;
    
    UILabel *detailOutAddressLabel = [[UILabel alloc] init];
    detailOutAddressLabel.numberOfLines = 0;
    detailOutAddressLabel.frame = CGRectMake(CGRectGetMaxX(addressLabel.frame), addressOutLabel.y, signView.width - OppositeWidthRate(10) -  CGRectGetMaxX(addressLabel.frame), OppositeHeightRate(Font12.lineHeight) * 2);
    detailOutAddressLabel.font = Font12;
    detailOutAddressLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    [signOutView addSubview:detailOutAddressLabel];
    self.signOutDetailLabel = detailOutAddressLabel;
    
    signOutView.height = CGRectGetMaxY(detailOutAddressLabel.frame) + OppositeHeightRate(10);
    
    
    
    UIImageView *qiandaoImage = [[UIImageView alloc] init];
    qiandaoImage.frame = CGRectMake(self.view.width - OppositeWidthRate(30) - 80.0f , self.signView.y, 80.0f, 80.0f);
    
    //    qiandaoImage.frame = CGRectMake(0, 0, shijianzouView.width, shijianzouView.height);
    qiandaoImage.image = [UIImage imageNamed:@"bigYinzhang"];
    qiandaoImage.hidden = YES;
    [shijianzouView addSubview:qiandaoImage];
    self.qiandaoImage = qiandaoImage;
    
    UIImageView *qiantuiImage = [[UIImageView alloc] init];
    qiantuiImage.frame = CGRectMake(self.view.width - OppositeWidthRate(30) - 80.0f , self.signOutView.y, 80.0f, 80.0f);
    //    qiantuiImage.frame = CGRectMake(0, 0, shijianzouView.width, shijianzouView.height);
    qiantuiImage.image = [UIImage imageNamed:@"bigSignOutYinzhang"];
    qiantuiImage.hidden = YES;
    [shijianzouView addSubview:qiantuiImage];
    self.qiantuiImage = qiantuiImage;
}


/*

#pragma mark - Sign TableView

- (void)creatSignProcedureView {
    
    CGRect rect = CGRectMake(0, 0, 0, 0);
    UITableView *tableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
    self.tableView = tableView;
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.layer.cornerRadius = 15;
    tableView.layer.masksToBounds = YES;
    [self.view addSubview:tableView];
    [self.view bringSubviewToFront:tableView];
//    tableView.hidden = YES;
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(100);
        make.bottom.mas_equalTo(-100);
    }];
}


#pragma mark -- dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WZSignListCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    cell.list = self.listArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WZMobileOutSignList *list = self.listArray[indexPath.row];
    
    // 打卡
    // 直接打开
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"userId"] = self.oaUserId;
    parameters[@"signFlag"] = self.signFlag;
    parameters[@"longitude"] = [NSString stringWithFormat:@"%f",self.userCoordiNate2D.longitude];
    parameters[@"latitude"] = [NSString stringWithFormat:@"%f",self.userCoordiNate2D.latitude];
    WZMobileOutSignList *signList = self.listArray.lastObject;
    parameters[@"modelId"] = list.modelId;
    parameters[@"mversion"] = list.mversion;
    parameters[@"fversion"] = list.fversion;
    parameters[@"startEventkey"] = list.startEventKey;
    
    [NetWorkShare OutMobileSignOrSignOutProcedureWithParameters:parameters successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([[responseObject objectForKey:@"success"] boolValue]) {
            
            [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
                [MBProgressHUD hideHUDForView:self.view];
                if (responseObject) {
                    NSLog(@"+++ = %@", responseObject);
                    if ([[responseObject objectForKey:@"success"] boolValue]) {
                        [self.mobileSignArray removeAllObjects];
                        [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                        
                        //数组排序
                        [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                            return [obj1.sign compare:obj2.sign];
                        }];
                        
                        if ([@"1" isEqualToString:self.signFlag]) {
                            self.qiandaoImage.hidden = NO;
                            [self addAnimationWithImageview:self.qiandaoImage];
                            [self setupData];
                        } else {
                            self.qiantuiImage.hidden = NO;
                            
                            [self addAnimationWithImageview:self.qiantuiImage];
                            [self setupData];
                        }
                        
                    } else {
                        [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
                    }
                    
                } else {
                    [MBProgressHUD showError:@"未知错误"];
                }
                
            } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
                [MBProgressHUD hideHUDForView:self.view];
                [MBProgressHUD showError:@"网络错误!" toView:self.view];
            }];
            
        } else {
            
            [MBProgressHUD hideHUDForView:self.view];
            [MBProgressHUD showError:[responseObject objectForKey:@"message"] toView:self.view];
        }
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络错误!" toView:self.view];
    }];
}


// 获取companyID
- (void)getCompanyIDWithUserCode:(NSString *)userCode {
    
    [[CXmppRequestMgr shareInstance] getCompanyInfoWithUserCode:userCode AndsuccessHandel:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            
            self.company_ID = responseObject[@"companyId"];
            WZLog(@"result = %@", responseObject);
        }
    } filarueHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD showError:@"获取公司ID失败"];
    }];
}

*/
 
/**获取系统时间*/
- (void)getcurrentTime {
    
    NSDate * senddate=[NSDate date];
    
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"HH:mm"];
    
//    NSString * locationString=[dateformatter stringFromDate:senddate];
    
    NSCalendar * cal=[NSCalendar currentCalendar];
    
    NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
    
    NSDateComponents * conponent= [cal components:unitFlags fromDate:senddate];
    
    NSInteger year=[conponent year];
    
    NSInteger month=[conponent month];
    
    NSInteger day=[conponent day];
    
    NSString * nsDateString= [NSString stringWithFormat:@"%4ld年%2ld月%2ld日",(long)year,(long)month,(long)day];
    
    WZLog(@"==== %@", nsDateString);
}


- (void)timerFunc {
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"HH:mm:ss"];
    
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
    [self.timeBtn setTitle:[NSString stringWithFormat:@"当前时间:%@",timestamp] forState:UIControlStateNormal];
    
//    NSLog(@"%@",timestamp);
}

//是否支持指纹
-(BOOL)isSupportfinger
{
    LAContext *context = [[LAContext alloc]init];
    BOOL ret = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];
    return ret;
}

- (void)signOutBtnChanged {
    
    self.signOutBtn.enabled = YES;
}


- (void)stampSignView {
    
    [NetWorkShare getMobileCurdaySignListWithUserId:self.oaUserId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view];
        if (responseObject) {
            NSLog(@"+++ = %@", responseObject);
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                [self.mobileSignArray removeAllObjects];
                [self.mobileSignArray addObjectsFromArray:[WZSign objectArrayWithKeyValuesArray:responseObject[@"list"]]];
                
                //数组排序
                [self.mobileSignArray sortUsingComparator:^NSComparisonResult(WZSign *obj1, WZSign *obj2) {
                    return [obj1.sign compare:obj2.sign];
                }];
                
                if ([@"1" isEqualToString:self.signFlag]) {
                    self.qiandaoImage.hidden = NO;
                    [self addAnimationWithImageview:self.qiandaoImage];
                    [self setupData];
                } else {
                    self.qiantuiImage.hidden = NO;
                    
                    [self addAnimationWithImageview:self.qiantuiImage];
                    [self setupData];
                }
                
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
            
        } else {
            [MBProgressHUD showError:@"未知错误"];
        }
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络错误!" toView:self.view];
    }];

}



#pragma mark - 懒加载

- (NSMutableArray *)listArray {
    
    if (_listArray == nil) {
        _listArray = [[NSMutableArray alloc] init];
    }
    return _listArray;
}

#pragma mark 懒加载
- (NSMutableArray *)mobileSignArray
{
    if (_mobileSignArray == nil) {
        _mobileSignArray = [NSMutableArray array];
    }
    return _mobileSignArray;
}


@end
